package com.jokerpan.project.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jokerpan.project.commons.PaginationBuilder;
import com.jokerpan.project.entity.Visitors;
import com.jokerpan.project.mapper.VisitorsMapper;
import com.jokerpan.project.service.VisitorsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author jokerpan
 */
@Service("visitorsService")
public class VisitorsServiceImpl implements VisitorsService {

    @Resource
    VisitorsMapper visitorsMapper;

    @Override
    public Map<String, Object> queryList(Visitors visitors) {
        Page<Object> page = PageHelper.startPage(visitors.getCurrentPage(), visitors.getPageSize());
        List<Visitors> resultList = this.visitorsMapper.queryList(visitors);
        return PaginationBuilder.buildResult(resultList, page.getTotal(), visitors.getCurrentPage(), visitors.getPageSize());
    }

    @Override
    public boolean add(Visitors visitors) {
        return visitorsMapper.add(visitors) > 0;
    }

    @Override
    public boolean deleteById(Integer id) {
        return visitorsMapper.deleteById(id) > 0;
    }
}
